package org.sippr.service.impl;

import org.sippr.mapper.SdStyleMapper;
import org.sippr.pojo.SdStyle;
import org.sippr.service.SdStyleService;
import org.sippr.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Service
public class SdStyleImpl implements SdStyleService {

    @Autowired
    private SdStyleMapper sdStyleMapper;

    @Override
    public void add(SdStyle value) {

        Map<String, Object> map = ThreadLocalUtil.get();
        String sid = (String) map.get("id");
        Integer id = Integer.parseInt(sid);
        value.setModifyUser(id);
        value.setCreateUser(id);

        //记录时间
        LocalDateTime time = LocalDateTime.now();
        value.setCreateTime(time);
        value.setUpdateTime(time);

        sdStyleMapper.insert(value);
    }

    @Override
    public List<SdStyle> findByName(String name) {
        return sdStyleMapper.findByName(name);
    }

    @Override
    public void update(SdStyle value) {


        Map<String, Object> map = ThreadLocalUtil.get();
        String sid = (String) map.get("id");
        Integer id = Integer.parseInt(sid);
        value.setModifyUser(id);

        LocalDateTime time = LocalDateTime.now();
        value.setUpdateTime(time);

        sdStyleMapper.updateByPrimaryKeySelective(value);
    }

    @Override
    public List<SdStyle> list() {
        return sdStyleMapper.list();
    }

    @Override
    public void delete(Integer id) {
        sdStyleMapper.deleteByPrimaryKey(id);
    }

    @Override
    public SdStyle get(Integer id) {
        return sdStyleMapper.selectByPrimaryKey(id);
    }

    @Override
    public void deleteCp(Integer id) {
        sdStyleMapper.deleteCp(id);
    }

    @Override
    public void deleteLorra(Integer id) {
        sdStyleMapper.deleteLorra(id);
    }
}
